define(function (required, exports, modules) {
  var modal = require('mods/modal');
  exports.member_down = function (ols) {
    $("." + ols).dropdown({
      on: "hover"
    });
  };

  exports.member_give = function () {
    $('.member-give').click(function () {
      if ($(this).hasClass("disabled")) {
        modal.alert("系统正在处理中~~~~,请稍后再试试")
        return false
      }

      var _crsf = $("#csrf").val()
      var integral_source = $("input[name=integral]").val();
      var member_id = $('input[name=member-id]').val();
      var integral = $("input[name=member-integral]").val()
      var give_integral = $("input[name=give-integral]").val()


      if (integral_source.length < 1) {
        modal.alert("请选择积分来源")
        return false
      }

      if (give_integral == '1' && integral.length < 1) {
        modal.alert("请填写给与的积分");
        return false
      }


      $(this).addClass('disabled');
      $.ajax({
        url: '/admin/member/give-integral',
        type: 'POST',
        dataType: 'json',
        data: {
          integral_source: integral_source,
          member_id: member_id,
          integral: integral,
          _csrf: _crsf
        },
        success: function (res) {
          $(this).removeClass("disabled")
          if (res.code == 200) {
            modal.msg(res.msg, {}, function () {
              location.href = "/admin/member/index"
            })
          } else {
            modal.msg(res.msg, {}, function () {
              location.reload()
              return false
            })
          }
        }
      })
    });
    $('input[name=integral]').change(function () {
      if ($(this).val() == '其他') {
        $(".member_integral").css('display', 'block')
        $("input[name=give-integral]").val("1")
        console.log($("input[name=give-integral]").val())
      } else {
        $('.member_integral').css('display', 'none')
        $("input[name=give-integral]").val("0")
        console.log($("input[name=give-integral]").val())
      }
    })
  };
})